package cloud.shyidong.core.response;

import java.util.Collections;
import java.util.List;

/**
 * @Description TODO
 * @Author syd
 * @Date 2023/3/27
 */
public class SimplePageResponse<T> implements PageResponse<T> {
    
    private long total = 0;
    
    private long size = 10;
    
    private long current = 1;
    
    private List<T> records = Collections.emptyList();
    
    public SimplePageResponse(long size, long current) {
        this(0, size, current);
    }
    
    public SimplePageResponse(long total, long size, long current) {
        this.total = total;
        if (size > 10) {
            this.size = size;
        }
        if (current > 1) {
            this.current = current;
        }
    }
    
    public long getTotal() {
        return total;
    }
    
    public SimplePageResponse setTotal(long total) {
        this.total = total;
        return this;
    }
    
    public long getSize() {
        return size;
    }
    
    public SimplePageResponse setSize(long size) {
        this.size = size;
        return this;
    }
    
    public long getCurrent() {
        return current;
    }
    
    public SimplePageResponse setCurrent(long current) {
        this.current = current;
        return this;
    }
    
    public List<T> getRecords() {
        return records;
    }
    
    public SimplePageResponse setRecords(List<T> records) {
        this.records = records;
        return this;
    }
    
    public long getPages() {
        if (total <= 0) {
            return 0;
        }
        long pages = this.total / this.size;
        if (this.total % this.size > 0) {
            pages++;
        }
        return pages;
    }
    
    public boolean hasPrevious() {
        return this.current > 1;
    }
    
    public boolean hasNext() {
        return this.current < this.getPages();
    }
    
}
